package com.omkarpatil.learningjpa2.mapping.onetoone.jointable.secondary;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity(name="OtoJoinSecondaryTableEmployee") 
@Table(name = "oto_join_sectable_emp")
@SecondaryTable(name = "oto_join_sectable_emp_desk")
public class Employee {
	
	private int id;
	private String name;
	private Desk desk;
	private Date allocationDate;
	
	public Employee() {}

	public Employee(String name) {
		this.name = name;
	}

	@Id 
	@GeneratedValue
	@Column(name = "emp_id")
	public int getId() {
		return id;
	}
	
	private void setId(int id) {
		this.id = id;
	}
	
	@Column(nullable = false, length = 30)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@OneToOne
	@JoinColumn(table = "oto_join_sectable_emp_desk", name = "desk_id", unique = true)
	public Desk getDesk() {
		return desk;
	}

	public void setDesk(Desk desk) {
		this.desk = desk;
	}

	@Temporal(TemporalType.DATE)
	@Column(table = "oto_join_sectable_emp_desk", nullable = false)
	public Date getAllocationDate() {
		return allocationDate;
	}

	public void setAllocationDate(Date allocationDate) {
		this.allocationDate = allocationDate;
	}	
}
